package exit.manboking.common;

import java.util.ArrayList;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


public class ViewFactory {

	private LayoutInflater mInflater;
	private ArrayList<Map<String,Object>> menulist;
	
	public ViewFactory(Context context,ArrayList<Map<String,Object>> menulist) {
		super();
		this.mInflater = LayoutInflater.from(context);
		this.menulist  = menulist;
	}

	public void setView(AdapterViewIfs ifs){
		ifs.setView(ifs);
	}
	
	public View parseView(int index){
		Map<String,Object> map = menulist.get(index);
		
		int style = (Integer) map.get("style");
		
		switch (style) {
		case Code.CODE_MENU_TITLE:
			return createTitleMenu(map);
		case Code.CODE_MENU_CONTENTS:
			return createContents(map);
		default:
			break;
		}
		return null;
	}
	
	private View createTitleMenu(Map<String, Object> map){
		View            view   = mInflater.inflate((Integer)map.get("layout_id"), null);
		TitleViewHolder holder = new TitleViewHolder();
		holder.textView = (TextView) view.findViewById((Integer)map.get("textView_id"));
		view.setTag(holder);
		return view;
	}
	
	private View createContents(Map<String, Object> map){
		View view = mInflater.inflate((Integer)map.get("layout_id"), null);
		
		return view;
	}
	
	class TitleViewHolder{
		TextView textView;
	}
	

}
